﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class WebPage_YingXiao_ShujuXiazai_User : MarketBBasePage
    {

        private void downshuju(string city, string type, string gender)
        {
            StringBuilder builder = new StringBuilder();
            if (((city == "") || (type == "")) || (gender == ""))
            {
                this.SetError("-ERR ERR_NO_DATA");
                base.Response.Redirect("YingXiao_ShujuXiazai_User.aspx");
            }
            else
            {
                int num2;
                builder.Append("<html>");
                builder.Append("<meta http-equiv=content-type content=\"text/html; charset=UTF-8\">");
                builder.Append("<body><table border='1'>");
                builder.Append("<tr>");
                builder.Append("<td>ID</td>");
                builder.Append("<td align='left'>用户ID</td>");
                builder.Append("<td>邮件</td>");
                builder.Append("<td>用户名</td>");
                builder.Append("<td>真实姓名</td>");
                builder.Append("<td>性别</td>");
                builder.Append("<td>QQ号码</td>");
                builder.Append("<td>手机号码</td>");
                builder.Append("<td>邮编</td>");
                builder.Append("<td>地址</td>");
                builder.Append("<td>购买</td>");
                builder.Append("</tr>");
                int num = 1;
                string[] strArray = type.Split(new char[] { ',' });
                string str = "";
                for (num2 = 0; num2 < strArray.Length; num2++)
                {
                    str = str + "'" + strArray[num2] + "',";
                }
                str = str.Substring(0, str.Length - 1);
                string[] strArray2 = gender.Split(new char[] { ',' });
                string str2 = "";
                for (num2 = 0; num2 < strArray2.Length; num2++)
                {
                    str2 = str2 + "'" + strArray2[num2] + "',";
                }
                str2 = str2.Substring(0, str2.Length - 1);
                Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
                foreach (Maticsoft.Model.UserInfo info2 in info.GetModelList(" City_id in (" + city + ") and Newbie in (" + str + ") and Gender in (" + str2 + ")"))
                {
                    builder.Append("<tr>");
                    builder.Append("<td>" + num++.ToString() + "</td>");
                    builder.Append("<td align='left'>" + info2.Id + "</td>");
                    builder.Append("<td>" + info2.Email + "</td>");
                    builder.Append("<td>" + info2.Username + "</td>");
                    builder.Append("<td>" + info2.Realname + "</td>");
                    if (info2.Gender.ToUpper() == "M")
                    {
                        builder.Append("<td>男</td>");
                    }
                    if (info2.Gender.ToUpper() == "F")
                    {
                        builder.Append("<td>女</td>");
                    }
                    builder.Append("<td>" + info2.Qq + "</td>");
                    builder.Append("<td>" + info2.Mobile + "</td>");
                    builder.Append("<td>" + info2.Zipcode + "</td>");
                    builder.Append("<td>" + info2.Address + "</td>");
                    if (info2.Newbie.ToUpper() == "Y")
                    {
                        builder.Append("<td>购买过</td>");
                    }
                    if (info2.Newbie.ToUpper() == "N")
                    {
                        builder.Append("<td>未购买</td>");
                    }
                    builder.Append("</tr>");
                }
                builder.Append("</table></body></html>");
                base.Response.ClearHeaders();
                base.Response.Clear();
                base.Response.Expires = 0;
                base.Response.Buffer = true;
                base.Response.AddHeader("Accept-Language", "zh-tw");
                base.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode("user_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", Encoding.UTF8));
                base.Response.ContentType = "Application/octet-stream";
                base.Response.Write(builder.ToString());
                base.Response.End();
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "yingxiao";
            this.YingXiao1.Select = "shuju";
            if (!base.IsPostBack)
            {
                this.setUser();
            }
            if (base.Request.HttpMethod == "POST")
            {
                if (((base.Request.Form["city_id"] != null) && (base.Request.Form["newbie"] != null)) && (base.Request.Form["gender"] != null))
                {
                    string city = base.Request.Form["city_id"].ToString();
                    string type = base.Request.Form["newbie"].ToString();
                    string gender = base.Request.Form["gender"].ToString();
                    this.downshuju(city, type, gender);
                }
                else
                {
                    this.SetError("-ERR ERR_NO_DATA");
                    base.Response.Redirect("YingXiao_ShujuXiazai_User.aspx");
                }
            }
        }

        private void setUser()
        {
            Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
            StringBuilder builder = new StringBuilder();
            foreach (Maticsoft.Model.Category category2 in category.GetModelList("Zone='city'"))
            {
                builder.Append(string.Concat(new object[] { "<input type='checkbox' name='city_id' value='", category2.Id, "' checked />&nbsp;", category2.Name, "&nbsp;&nbsp;" }));
            }
            this.Literal1.Text = builder.ToString();
        }
    }


